package org.auf.controllers;

import java.io.IOException;

import org.auf.core.Controller;
import org.auf.core.UIDGenerator;
import org.auf.model.ITestDAO;
import org.auf.model.Test;
import org.auf.model.TestDAOJDBC;
import org.auf.model.User;

public class NewUserController extends Controller {

	@Override
	public void show() {
		//TODO: Pendiente de revision
		User temp = new User();
		String name, password, mail, geek, score, id, idTest;
		name = (String) request.getAttribute("name");
		password = (String) request.getAttribute("password");
		mail = (String) request.getAttribute("mail");
		geek = (String) request.getAttribute("geek"); // geek o volunteer
		score = (String) request.getAttribute("score");
		id = UIDGenerator.getInstance().getKey();
		temp.setId(id);
		temp.setMail(mail);
		temp.setName(name);
		temp.setPassword(password);
		temp.setGeek(geek.equals("true")); //cambiarlo
		temp.setScore(Integer.valueOf(score));
		request.setAttribute("userTemp", temp);
		Test exam = new Test();
		ITestDAO testdao = new TestDAOJDBC();
		exam = testdao.selectRamdomTest();
		idTest = exam.getId();
		try {
			response.sendRedirect("?action=showtest&=id" + idTest);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
